/*
  Copyright � 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  ThanhNam ERP Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using VINETLIFE.DO;
/// <summary>
/// Summary description for cmsDoiTacDAL
/// </summary>
namespace VINETLIFE.DAL
{

    public class cmsDoiTacDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public cmsDoiTacDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(cmsDoiTacDO objcmsDoiTacDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsDoiTac_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@TenDoiTac", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsDoiTacDO.TenDoiTac;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ImageUrl", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsDoiTacDO.ImageUrl;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MoTa", SqlDbType.NText);
            Sqlparam.Value = objcmsDoiTacDO.MoTa;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderID", SqlDbType.Int);
            Sqlparam.Value = objcmsDoiTacDO.OrderID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Type", SqlDbType.Int);
            Sqlparam.Value = objcmsDoiTacDO.Type;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Thumbnail", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsDoiTacDO.Thumbnail;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MaDoiTac", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsDoiTacDO.MaDoiTac;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Description", SqlDbType.NText);
            Sqlparam.Value = objcmsDoiTacDO.Description;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Address", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsDoiTacDO.Address;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DienThoai", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsDoiTacDO.DienThoai;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Website", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsDoiTacDO.Website;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MoTaChiTiet", SqlDbType.NText);
            Sqlparam.Value = objcmsDoiTacDO.MoTaChiTiet;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@GiamGia", SqlDbType.Int);
            Sqlparam.Value = objcmsDoiTacDO.GiamGia;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(cmsDoiTacDO objcmsDoiTacDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsDoiTac_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@DoiTacID", SqlDbType.Int);
            Sqlparam.Value = objcmsDoiTacDO.DoiTacID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@TenDoiTac", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsDoiTacDO.TenDoiTac;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ImageUrl", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsDoiTacDO.ImageUrl;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MoTa", SqlDbType.NText);
            Sqlparam.Value = objcmsDoiTacDO.MoTa;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderID", SqlDbType.Int);
            Sqlparam.Value = objcmsDoiTacDO.OrderID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Type", SqlDbType.Int);
            Sqlparam.Value = objcmsDoiTacDO.Type;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Thumbnail", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsDoiTacDO.Thumbnail;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MaDoiTac", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsDoiTacDO.MaDoiTac;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Description", SqlDbType.NText);
            Sqlparam.Value = objcmsDoiTacDO.Description;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Address", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsDoiTacDO.Address;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DienThoai", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsDoiTacDO.DienThoai;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Website", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsDoiTacDO.Website;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MoTaChiTiet", SqlDbType.NText);
            Sqlparam.Value = objcmsDoiTacDO.MoTaChiTiet;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@GiamGia", SqlDbType.Int);
            Sqlparam.Value = objcmsDoiTacDO.GiamGia;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(cmsDoiTacDO objcmsDoiTacDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsDoiTac_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@DoiTacID", SqlDbType.Int);
            Sqlparam.Value = objcmsDoiTacDO.DoiTacID;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsDoiTac_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public cmsDoiTacDO Select(cmsDoiTacDO objcmsDoiTacDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsDoiTac_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@DoiTacID", SqlDbType.Int);
            Sqlparam.Value = objcmsDoiTacDO.DoiTacID;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["DoiTacID"]))
                    objcmsDoiTacDO.DoiTacID = Convert.ToInt32(dr["DoiTacID"]);
                if (!Convert.IsDBNull(dr["TenDoiTac"]))
                    objcmsDoiTacDO.TenDoiTac = Convert.ToString(dr["TenDoiTac"]);
                if (!Convert.IsDBNull(dr["ImageUrl"]))
                    objcmsDoiTacDO.ImageUrl = Convert.ToString(dr["ImageUrl"]);
                if (!Convert.IsDBNull(dr["MoTa"]))
                    objcmsDoiTacDO.MoTa = Convert.ToString(dr["MoTa"]);
                if (!Convert.IsDBNull(dr["OrderID"]))
                    objcmsDoiTacDO.OrderID = Convert.ToInt32(dr["OrderID"]);
                if (!Convert.IsDBNull(dr["Type"]))
                    objcmsDoiTacDO.Type = Convert.ToInt32(dr["Type"]);
                if (!Convert.IsDBNull(dr["Thumbnail"]))
                    objcmsDoiTacDO.Thumbnail = Convert.ToString(dr["Thumbnail"]);
                if (!Convert.IsDBNull(dr["MaDoiTac"]))
                    objcmsDoiTacDO.MaDoiTac = Convert.ToString(dr["MaDoiTac"]);
                if (!Convert.IsDBNull(dr["Description"]))
                    objcmsDoiTacDO.Description = Convert.ToString(dr["Description"]);
                if (!Convert.IsDBNull(dr["Address"]))
                    objcmsDoiTacDO.Address = Convert.ToString(dr["Address"]);
                if (!Convert.IsDBNull(dr["DienThoai"]))
                    objcmsDoiTacDO.DienThoai = Convert.ToString(dr["DienThoai"]);
                if (!Convert.IsDBNull(dr["Website"]))
                    objcmsDoiTacDO.Website = Convert.ToString(dr["Website"]);
                if (!Convert.IsDBNull(dr["MoTaChiTiet"]))
                    objcmsDoiTacDO.MoTaChiTiet = Convert.ToString(dr["MoTaChiTiet"]);
                if (!Convert.IsDBNull(dr["GiamGia"]))
                    objcmsDoiTacDO.GiamGia = Convert.ToInt32(dr["GiamGia"]);

            }
            return objcmsDoiTacDO;
        }

        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsDoiTac_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsDoiTacDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    cmsDoiTacDO objcmsDoiTacDO = new cmsDoiTacDO();
                    if (!Convert.IsDBNull(dr["DoiTacID"]))
                        objcmsDoiTacDO.DoiTacID = Convert.ToInt32(dr["DoiTacID"]);
                    if (!Convert.IsDBNull(dr["TenDoiTac"]))
                        objcmsDoiTacDO.TenDoiTac = Convert.ToString(dr["TenDoiTac"]);
                    if (!Convert.IsDBNull(dr["ImageUrl"]))
                        objcmsDoiTacDO.ImageUrl = Convert.ToString(dr["ImageUrl"]);
                    if (!Convert.IsDBNull(dr["MoTa"]))
                        objcmsDoiTacDO.MoTa = Convert.ToString(dr["MoTa"]);
                    if (!Convert.IsDBNull(dr["OrderID"]))
                        objcmsDoiTacDO.OrderID = Convert.ToInt32(dr["OrderID"]);
                    if (!Convert.IsDBNull(dr["Type"]))
                        objcmsDoiTacDO.Type = Convert.ToInt32(dr["Type"]);
                    if (!Convert.IsDBNull(dr["Thumbnail"]))
                        objcmsDoiTacDO.Thumbnail = Convert.ToString(dr["Thumbnail"]);
                    if (!Convert.IsDBNull(dr["MaDoiTac"]))
                        objcmsDoiTacDO.MaDoiTac = Convert.ToString(dr["MaDoiTac"]);
                    if (!Convert.IsDBNull(dr["Description"]))
                        objcmsDoiTacDO.Description = Convert.ToString(dr["Description"]);
                    if (!Convert.IsDBNull(dr["Address"]))
                        objcmsDoiTacDO.Address = Convert.ToString(dr["Address"]);
                    if (!Convert.IsDBNull(dr["DienThoai"]))
                        objcmsDoiTacDO.DienThoai = Convert.ToString(dr["DienThoai"]);
                    if (!Convert.IsDBNull(dr["Website"]))
                        objcmsDoiTacDO.Website = Convert.ToString(dr["Website"]);
                    if (!Convert.IsDBNull(dr["MoTaChiTiet"]))
                        objcmsDoiTacDO.MoTaChiTiet = Convert.ToString(dr["MoTaChiTiet"]);
                    if (!Convert.IsDBNull(dr["GiamGia"]))
                        objcmsDoiTacDO.GiamGia = Convert.ToInt32(dr["GiamGia"]);
                    arrcmsDoiTacDO.Add(objcmsDoiTacDO);
                }
            }
            return arrcmsDoiTacDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsDoiTac_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public DataTable SelectByTypeAndTop(int top,int type)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "cmsDoiTac_GetByTypeAndTop";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Top", SqlDbType.Int);
            Sqlparam.Value = top;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Type", SqlDbType.Int);
            Sqlparam.Value = type;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectByTypeAdmin(int type)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "cmsDoiTac_GetByTypeAdmin";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Type", SqlDbType.Int);
            Sqlparam.Value = type;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        #endregion

    }

}
